package com.action.blog;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.db.blogboard.BoardDAO;
import com.db.blogboard.BoardFindVO;
import com.db.blogboard.BoardVO;
import com.opensymphony.xwork2.ActionContext;

public class MainContentAction {
	private BoardDAO blogboard;
	private int blisttype;
	private int plisttype;
	private int ono;
	private List<BoardVO> blist = new ArrayList<BoardVO>();
	private List<BoardVO> plist = new ArrayList<BoardVO>();

	private int line;

	public BoardDAO getBlogboard() {
		return blogboard;
	}

	public void setBlogboard(BoardDAO blogboard) {
		this.blogboard = blogboard;
	}

	public List<BoardVO> getBlist() {
		return blist;
	}

	public void setBlist(List<BoardVO> blist) {
		this.blist = blist;
	}

	public List<BoardVO> getPlist() {
		return plist;
	}

	public void setPlist(List<BoardVO> plist) {
		this.plist = plist;
	}

	public int getBlisttype() {
		return blisttype;
	}

	public void setBlisttype(int blisttype) {
		this.blisttype = blisttype;
	}

	public int getPlisttype() {
		return plisttype;
	}

	public void setPlisttype(int plisttype) {
		this.plisttype = plisttype;
	}

	public int getLine() {
		return line;
	}

	public int getOno() {
		return ono;
	}

	public void setOno(int ono) {
		this.ono = ono;
	}

	public String execute() throws Exception {

		if (blisttype == 1) {
			BoardFindVO vo = new BoardFindVO();
			Map session = ActionContext.getContext().getSession();
			vo.setIdtype(session.get("idtype").toString());
			vo.setJsptype(blisttype);

			blist = list(vo);
		}

		if (plisttype == 2) {
			BoardFindVO vo = new BoardFindVO();
			Map session = ActionContext.getContext().getSession();
			vo.setIdtype(session.get("idtype").toString());
			vo.setJsptype(plisttype);

			plist = list(vo);
		}
		return "success";
	}

	public List list(BoardFindVO fvo) throws Exception {

		List<BoardVO> list = new ArrayList<BoardVO>();

		List<BoardVO> temp = blogboard.boardAllData(fvo);

		int j = temp.size();

		if (j > 5) {
			j = 5;
		}

		for (int i = 0; i < j; i++) {

			BoardVO vo = temp.get(i);

			list.add(vo);

		}

		return list;
	}

	public List bplist(BoardFindVO fvo) throws Exception {
		List<BoardVO> list = new ArrayList<BoardVO>();

		List<BoardVO> temp = blogboard.boardAllData(fvo);
				
		int j = temp.size();

		if (j > 5) {
			j = 5;
		}

		for (int i = 0; i < j; i++) {

			BoardVO vo = temp.get(i);

			list.add(vo);

		}

		return list;
	}
}
